package com.scau.clothes.stock.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scau.clothes.core.util.CheckObjectIsNullUtils;
import com.scau.clothes.stock.mapper.ColorMapper;
import com.scau.clothes.stock.model.entity.Color;
import com.scau.clothes.stock.service.ColorService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ColorServiceImpl extends ServiceImpl<ColorMapper, Color> implements ColorService {

    @Resource
    private ColorMapper colorMapper;
    private CheckObjectIsNullUtils checkObjectIsNullUtils = new CheckObjectIsNullUtils();

    @Override
    public int insertColor(Color color) {
        return colorMapper.insert(color);
    }

    @Override
    public int updateColor(Color color) {
        color.setIsDelete(0);
        return colorMapper.updateById(color);
    }

    @Override
    public int deleteColor(Color color) {
        color.setIsDelete(1);
        return colorMapper.updateById(color);
    }

    @Override
    public List<Color> listAllColor(Color color) {
        QueryWrapper<Color> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("is_delete", 1);
        if (!checkObjectIsNullUtils.objCheckIsNull(color)){
            if (color.getColorId()!=null)
                queryWrapper.eq("color_id", color.getColorId());
            if (color.getColorName() != null)
                queryWrapper.like("color_name", color.getColorName());
        }
        List<Color> list = list(queryWrapper);
        return list;
    }
}
